﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using PowerCreator.LMS.Refer.Entity;
using PowerCreator.LMS.Web.Refer;
using PowerCreator.LMS.Common.Script;
public partial class sysadmin_ReferManager_ManagerRefer : PowerCreator.LMS.Web.Base.WebBasePage
{
    Refer objrefer = new Refer();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, 1);
        }
    }

    protected override void InitPage()
    {
        lbl_InfoTitle_ManagerRefer.Text = GetLanageValueByKey("lab_ManagerRefer_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_ManagerRefer.Text = GetLanageValueByKey("lab_ManagerRefer_QuestionList", PowerCreator.LMS.Language.LanagetItemType.Page);

        btnSearch.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnAddNew.Text = GetLanageValueByKey("btn_AddNew", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();

        //btnAddNew.Visible = false;
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //    btnAddNew.Visible = true;

    }
    private string GetSearch()
    {
        string search = string.Format("ReferTitle like '%{0}%'", txtReferTitle.Text.Trim());
        return search;
    }

    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        string url = "AddRefer.aspx";
        Script.RedirectURL(url);
    }
    protected void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objrefer.Count(search);
        AspNetPager1.PageSize = LMSPageSize;
    }
    private void BinderPG(string search,int pageIndex)
    {
        string orderlist = " ReferID Desc";
        DataTable dt = objrefer.Query(search,orderlist, LMSPageSize, pageIndex);
        rptRefer.DataSource = dt;
        rptRefer.DataBind();     
    }  

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderPG(search,1);
    }
  
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPG(search, AspNetPager1.CurrentPageIndex);
    }
    protected void rptRefer_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Label lbl_msg = (Label)e.Item.FindControl("lbl_msg");
        if (e.CommandName.ToLower() == "anser")
        {
            //if (IsLicensed("ReversionAdd"))
            //{
                string url = "AddReversion.aspx?ReferID=" + e.CommandArgument.ToString();
                Script.RedirectURL(url);
            //}
            //else
            //{ 
                
            //}
        }
        else if (e.CommandName.ToLower() == "ldel")
        {
            objrefer.Del(int.Parse(e.CommandArgument.ToString()));
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, AspNetPager1.CurrentPageIndex);
        }
        else if (e.CommandName.ToLower() == "ischeck")
        {
            VOTRefer vo = new VOTRefer();
            vo = objrefer.Load(int.Parse(e.CommandArgument.ToString()));
            if (vo.ReferState == true)
                vo.ReferState = false;
            else
                vo.ReferState = true;
            objrefer.Update(vo);
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, AspNetPager1.CurrentPageIndex);
        }

    }
    protected void rptRefer_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            LinkButton lbtn = (LinkButton)e.Item.FindControl("lnkbtn_del");
            lbtn.Attributes.Add("onClick", "javascript:return confirm('确定删除此记录？');");
        }
    }
}
